#include "DXUT.h"

#include "SDKmisc.h"

CFileTexture::CFileTexture( const TCHAR * resName,const TCHAR * szFilePath, D3DPOOL pool /*= D3DPOOL_DEFAULT*/,D3DCOLOR dwColorKey /*= 0*/ )
 :ITexture(RESOURCE_TYPE_TEXTURE,resName,pool) ,	 m_dwColorKey  (dwColorKey)	  
{
	TCHAR path[MAX_PATH];
	DXUTFindDXSDKMediaFileCch(path,MAX_PATH,szFilePath);
	wcscpy_s( m_szFilePath, MAX_PATH, path );
}

CFileTexture::~CFileTexture( void )
{
 
}

 
HRESULT CFileTexture::OnD3D9ResetDevice( IDirect3DDevice9* pd3dDevice )
{
	HRESULT hr ;

	D3DXIMAGE_INFO info;
	hr = D3DXCreateTextureFromFileEx( pd3dDevice, GetFileName(), D3DX_DEFAULT, D3DX_DEFAULT,1, 0, D3DFMT_UNKNOWN, GetPoolType(),
		D3DX_DEFAULT, D3DX_DEFAULT,m_dwColorKey,
		&info, NULL, &m_pD3DTexture );


	if( FAILED( hr ) )
	{
		DXTRACE_ERR_MSGBOX( GetFileName(),hr);
		return hr;
	}

	m_dwWidth = info.Width;
	m_dwHeight = info.Height;

 
	return hr;
}

void CFileTexture::OnD3D9LostDevice()
{
 
	SAFE_RELEASE( m_pD3DTexture );
 
}

 